
export const wxPayment = (option) => {
  const options = {
    timeStamp: '',
    nonceStr: '',
    prepayid: '',
    paySign: '',
    ...option
  }
  return new Promise((resolve, reject) => {
	  console.log(options)
	  // #ifdef APP-PLUS
	  let obj = {
			"appid":option.appId,
			"noncestr": option.nonceStr,
			"prepayid": option.prepayid,
			"package": "Sign=WXPay",
			"partnerid":option.mchid,
			"timestamp": option.timeStamp,
			"sign":option.paySign
		}
		// let payObj = {
		// 	appid:"wxbf34f4f4a320dd42",
		// 	timeStamp:new Date().getTime(),
		// 	key:""
		// }
		// payObj.paySign = md5.hexMD5('appId=' + payObj.appid + '&nonceStr=' + res.data.data.nonce_str + '&package=' + res.data.data.prepay_id + '&signType=MD5&timeStamp=' + payObj.timeStamp + "&key=" + payObj.key).toUpperCase();
		// console.log(obj)
	  console.log(obj)
	  uni.requestPayment({
	    provider: 'wxpay',
		orderInfo: obj,
	    success: res => resolve(res),
	    fail: res => reject(res)
	  })
	  // #endif
	  // #ifdef MP-WEIXIN
	  uni.requestPayment({
	    provider: 'wxpay',
	    timeStamp: options.timeStamp,
	    nonceStr: options.nonceStr,
	    package: options.package,
	    signType: 'RSA',
	    paySign: options.paySign,
	    success: res => resolve(res),
	    fail: res => reject(res)
	  })
	  // #endif
	  // #ifdef H5
		function onBridgeReady(){
			// alert(objs.timestamp)
			WeixinJSBridge.invoke(
				'getBrandWCPayRequest', option,
				function(res) {
					if (res.err_msg == "get_brand_wcpay_request:ok") {
						resolve(res)
					}else{
						reject(res)
					}
				})
		}
		if (typeof WeixinJSBridge == "undefined") {
			if (document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', onBridgeReady(), false);
			} else if (document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', onBridgeReady());
				document.attachEvent('onWeixinJSBridgeReady', onBridgeReady());
			}
		} else {
			onBridgeReady();
		}
		// #endif
  })
}

export const zfbPayment = (option) => {
  
  return new Promise((resolve, reject) => {
    uni.requestPayment({
      provider: 'alipay',
      orderInfo: option,
      success: res => resolve(res),
      fail: res => reject(res)
    })
  })
}